package com.aplink.generic.xmlparser.ctrlformat;

import org.w3c.dom.Node;

import android.text.TextUtils;

import com.aplink.generic.constant.type.DateTimePickerType;
import com.aplink.generic.pojo.controlspec.DateTimePickerSpec;
import com.aplink.generic.xmlparser.XmlPaserUtil;

public class DateTimeFormat {
	public static final String DATE_VALUE_CONTROL = "dateValueControl";
	public static final String DISPLAY_FORMAT = "displayFormat";
	public static final String FULL_VALUE_CONTROL = "fullValueControl";
	public static final String IS_24_HOUR = "is24Hour";
	public static final String PICKER_MODE = "mode";
	public static final String TIME_VALUE_CONTROL = "timeValueControl";

	public static DateTimePickerSpec parse(final Node node) {
		final DateTimePickerSpec dateTimePickerSpec = new DateTimePickerSpec();
		if (node.hasAttributes()) {
			String value = XmlPaserUtil.getAttrValue(node,
					DateTimeFormat.FULL_VALUE_CONTROL);
			if (!TextUtils.isEmpty(value)) {
				dateTimePickerSpec.setFullValueControl(value);
			}

			value = XmlPaserUtil.getAttrValue(node,
					DateTimeFormat.DATE_VALUE_CONTROL);
			if (!TextUtils.isEmpty(value)) {
				dateTimePickerSpec.setDateValueControl(value);
			}

			value = XmlPaserUtil.getAttrValue(node,
					DateTimeFormat.TIME_VALUE_CONTROL);
			if (!TextUtils.isEmpty(value)) {
				dateTimePickerSpec.setTimeValueControl(value);
			}

			value = XmlPaserUtil.getAttrValue(node,
					DateTimeFormat.DISPLAY_FORMAT);
			if (!TextUtils.isEmpty(value)) {
				dateTimePickerSpec.setDisplayFormat(value);
			}

			value = XmlPaserUtil.getAttrValue(node, DateTimeFormat.IS_24_HOUR);
			if (!TextUtils.isEmpty(value)) {
				if (value.equalsIgnoreCase("Y")) {
					dateTimePickerSpec.setIs24Hour(true);
				}
			}
			value = XmlPaserUtil.getAttrValue(node, DateTimeFormat.PICKER_MODE);
			if (!TextUtils.isEmpty(value)) {
				dateTimePickerSpec.setDateTimePickerType(DateTimePickerType
						.get(value));
			}
		}
		return dateTimePickerSpec;
	}
}
